﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class mobile_mylottery : System.Web.UI.Page
{
    protected DataTable result = new DataTable();
    string ind_id;
    protected void Page_Load(object sender, EventArgs e)
    {
         ind_id = this.Request.Params["indid"];
         if (ind_id == null)
         {
             Page.RegisterStartupScript("ss", "<script>alert('登陆出错！')</script>");
             return;//后期添加手机错误转向页面
         }
         else
         {
             if (!IsPostBack)
             {
                 try
                 {
                     result.Columns.Add("l_title", typeof(string));
                     result.Columns.Add("l_sprize", typeof(string));
                     result.Columns.Add("l_tprize", typeof(string));
                     result.Columns.Add("l_fprize", typeof(string));
                     result.Columns.Add("l_start", typeof(DateTime));
                     result.Columns.Add("l_end", typeof(DateTime));
                     result.Columns.Add("l_rules", typeof(string));
                     result.Columns.Add("l_date", typeof(DateTime));
                     result.Columns.Add("l_aw", typeof(string));
                     SqlConnection sc1 = new SqlConnection(ConfigurationManager.ConnectionStrings["wbkpt"].ConnectionString.ToString());
                     sc1.Open();
                     SqlCommand get_lottery = new SqlCommand();
                     get_lottery.Connection = sc1;
                     get_lottery.CommandText = "select INFO_LOTTERY.LOTTERY_TITLE,INFO_LOTTERY.LOTTERY_START,INFO_LOTTERY.LOTTERY_END,INFO_LOTTERY.RULES,LOTTERY_ATTEND.ATTEND_DATE,LOTTERY_ATTEND.AWARD,a.PRODUCT_NAME as 'FPRIZE',b.PRODUCT_NAME as 'SPRIZE',c.PRODUCT_NAME as 'TPRIZE' from INFO_PRODUCT as a,INFO_PRODUCT as b,INFO_PRODUCT as c,INFO_LOTTERY,LOTTERY_ATTEND where INFO_LOTTERY.LOTTERY_ID=LOTTERY_ATTEND.LOTTERY_ID and LOTTERY_ATTEND.IND_ID=@id and INFO_LOTTERY.FPRIZE_ID=a.PRODUCT_ID and INFO_LOTTERY.SPRIZE_ID=b.PRODUCT_ID and INFO_LOTTERY.TPRIZE_ID=c.PRODUCT_ID";
                     get_lottery.Parameters.AddWithValue("@id", ind_id);
                     SqlDataReader r = get_lottery.ExecuteReader();
                     while (r.Read())
                     {

                         DataRow row = result.NewRow();
                         row["l_title"] = r.GetString(r.GetOrdinal("LOTTERY_TITLE"));               
                         row["l_fprize"] =  r.GetString(r.GetOrdinal("FPRIZE"));
                         row["l_sprize"] = r.GetString(r.GetOrdinal("SPRIZE"));
                         row["l_tprize"] =r.GetString(r.GetOrdinal("TPRIZE"));
                         row["l_start"] = r.GetDateTime(r.GetOrdinal("LOTTERY_START"));
                         row["l_end"] = r.GetDateTime(r.GetOrdinal("LOTTERY_END"));
                         row["l_rules"] = r.GetString(r.GetOrdinal("RULES"));

                         row["l_date"] = r.GetDateTime(r.GetOrdinal("ATTEND_DATE"));
                         int o = r.GetInt32(r.GetOrdinal("AWARD"));
                         if (o == 1)
                             row["l_aw"] = "一等奖";
                         else if (o == 2)
                             row["l_aw"] = "二等奖";
                         else if(o==3)
                             row["l_aw"] = "三等奖";
                         else
                             row["l_aw"] = "您没有获奖";

                         result.Rows.Add(row);
                     }
                     r.Close();

                     DataBind();
                     sc1.Close();
                 }
                 catch (Exception ss)
                 {
                     Page.RegisterStartupScript("ss", "<script>alert('" + ss.Message + ss.StackTrace + "！')</script>");
                     return;
                 }
             }
         }
    }
}